﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Diagnostics;
using FNBoard;
using System.Reflection.Metadata;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;

namespace FNBoard
{

internal class HotKey
    {
        //(注意)每个函数上方需要说明是调用系统API来源
        //[DllImport("user32.dll", SetLastError = true)]

        /// <summary>
        /// 注册热键,调用系统API,非托管RegisterHotKey
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="id"></param>
        /// <param name="fsModifiers"></param>
        /// <param name="vk"></param>
        /// <returns></returns>
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool RegisterHotKey(IntPtr hWnd, int id, KeyModifiers fsModifiers, Keys vk);

        /// <summary>
        /// 注销热键,调用系统API,非托管UnregisterHotKey
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        [DllImport("user32.dll", SetLastError = true)]
        public static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        public enum KeyModifiers
        {
            None=0,Alt=1,Ctrl=2,Shift=4,windowsKey=8,CtrlShift=6
        }

    }
}

////执行快捷键编号100,101
//protected override void WndProc(ref Message m)
//{
//    const int WM_HOTKEY = 0x0312;
//    //对应快捷键
//    switch (m.Msg)
//    {
//        case WM_HOTKEY:
//            switch (m.WParam.ToInt32())
//            {
//                case 100://按下的是Alt+1
//                    Debug.WriteLine("xxxxx");
//                    break;
//                case 101://按下的是Alt+2
//                    Debug.WriteLine("yyyyy");
//                    break;
//            }
//            break;
//    }
//    base.WndProc(ref m);
//}



//if (checkBox5.Checked)
//{
//    //快捷键Alt+1
//    alt1 = HotKey.RegisterHotKey(Handle, 100, HotKey.KeyModifiers.Alt, Keys.D1);
//    //快捷键Alt+2
//    alt1 = HotKey.RegisterHotKey(Handle, 101, HotKey.KeyModifiers.Alt, Keys.D2);
//    Debug.WriteLine("OpenHokey");

//}
//else
//{
//    //注销快捷键
//    HotKey.UnregisterHotKey(Handle, 100);
//    HotKey.UnregisterHotKey(Handle, 101);
//    Debug.WriteLine("closeHokey");
//}